<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearList"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        :label="$t('message.ddbh')"
        min-width="250"
        prop="orderId"
      />
      <el-table-column
        align="center"
        :label="$t('message.yhxx')"
        min-width="200"
        prop="memberInfo"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.kcmc')"
        min-width="200"
        prop="courseName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.kclx')"
        min-width="100"
        prop="orderId"
      >
        <template slot-scope="scope">
          {{ scope.row.courseType == '1' ? $t('message.ttk') :scope.row.courseType == '3' ?$t('message.cqk'): $t('message.sjk') }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.kcjgy')"
        prop="allPrice"
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.zffs')"
        min-width="120"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.payMethod">{{ nameWithPayMethod(scope.row.payMethod) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.tksj2')"
        prop="refundTime"
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="$t('message.tkje2')"
        prop="refundMoney"
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.tkyy2')"
        prop="refundNote"
        min-width="200"
      />
      <!-- <el-table-column
        align="center"
        :label="$t('message.czr')"
        prop="userName"
        min-width="200"
      /> -->
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { refundCourseList, allConfigList } from '@/api'
import { queryFormConfig } from './config'
import QueryForm from '@/components/QueryForm'
export default {
  name: 'OfflinecoursesRefund',
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig,
      meta: [],
      list: [],
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      payList: [
        { value: '01', label: this.$t('message.hyk') },
        { value: '02', label: this.$t('message.xj') },
        { value: '03', label: this.$t('message.wx') },
        { value: '04', label: this.$t('message.zfb') }
      ],
      filters: {},
      listLoading: true,
      allPayMethedList: []
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.pdgj()
    this.getList(1)
  },
  activated() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    pdgj() {
      allConfigList({ param: { type: '2', code: '1' }}).then(res => {
        if (res.errorCode === '000000') {
          this.allPayMethedList = res.recordList
          const arrb = res.recordList
          arrb.forEach(e => {
            e.label = e.name
          })
          this.queryFormConfig.formItems[3].options = arrb
        }
      }).catch(err => {
        console.log(err)
      })
    },
    nameWithPayMethod(payM) {
      const obj = this.allPayMethedList.find(item => item.value === payM)
      if (obj) {
        return obj.name
      } else {
        return '-'
      }
    },
    clearList() {
      this.filters = {}
      this.getList(1)
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      refundCourseList({ pagination, param: { venueId, ...filters }})
        .then(res => {
          this.listLoading = false
          if (res.errorCode === '000000') {
            this.list = res.recordList
            this.total = res.totalCount
          }
        })
        .catch(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
